<template>
  <div>
    <router-link
    tag="div"
    class="header-abs"
    to="/"
    v-show="showAbs"
    >
        <div class="iconfont header-abs-back">&#xe658;</div>
    </router-link>
    <div
    class="header-fixed"
    v-show="!showAbs"
    :style="opacityStyle"
    >
      <router-link to="/">
          <div class="iconfont header-fixed-back">&#xe658;</div>
      </router-link>
        景点详情
    </div>
  </div>
</template>

<script>
  export default{
    name :"DetailHeader",
    data () {
      return {
        showAbs: true,
        opacityStyle :0
      }
    },
    methods:{
      handleScroll () {
        const top = document.documentElement.scrollTop;
        if (top > 60 ) {
          let opacity = top/140
          opacity = opacity > 1 ? 1 : opacity
          this.opacityStyle = { opacity}
          this.showAbs = false
        } else{
          this.showAbs = true
        }
      }
    },
    mounted(){
      window.addEventListener('scroll',this.handleScroll)
    },
    activated () {
      window.addEventListener('scroll',this.handleScroll)
    },
    deactivated () {
      window.removeEventListener('scroll',this.handleScroll)
    }
  }
</script>

<style lang="stylus" scoped="scoped">
  @import '~styles/varibles.styl'
  .header-abs
    text-align :center
    position :absolute
    left :.2rem
    top :.2rem
    width :.8rem
    height :.8rem
    line-height :.8rem
    border-radius :.8rem
    background-color :rgba(0,0,0,.5)
    .header-abs-back
      font-size :.6rem
      color :#fff
  .header-fixed
    position :fixed;
    top :0;
    left :0
    right :0
    z-index :1
    color :#fff
    text-align :center
    height :$headerHeight
    line-height : $headerHeight
    background :$bgColor
    .header-fixed-back
     text-align :center
     font-size :0.6rem
     position :absolute
     left :0
     top :0
     width :.64rem
     color :#fff
</style>